<?php

namespace App\Admin\Exports;

use App\Models\AdminDmModel;
use App\Models\PaymentMethodModel;
use Encore\Admin\Grid\Exporters\ExcelExporter;
use Maatwebsite\Excel\Concerns\WithColumnWidths;
use Maatwebsite\Excel\Concerns\WithMapping;

class WithdrawExport extends ExcelExporter implements WithMapping, WithColumnWidths
{
    protected $fileName = '提现记录.xls';

    protected $headings = [
        '序列号',
        '提现方式',
        '提现人',
        '提现账号',
        '开户行',
        '提现金额',
        '打款凭证',
        '备注',
        '打款时间',
        '操作人'
    ];

    public function map($withdraw): array
    {
        $adminDm = AdminDmModel::query()
            ->where('user_id', $withdraw->operate_id)->first();
        $paymentMethod = PaymentMethodModel::query()
            ->where('id', $withdraw->payment_method_id)->first();

        return [
            $withdraw->serial_number,
            $paymentMethod->name,
            $withdraw->name,
            "\t" . $withdraw->identity.' ' . "\t",
            $withdraw->bank_name,
            $withdraw->amount,
            config('oss.url').fileIdToUrl($withdraw->file_id),
            $withdraw->remark,
            $withdraw->pay_at,
            $adminDm->name,
        ];
    }

    public function columnWidths(): array
    {
        return [
            'A' => 25,
            'B' => 20,
            'C' => 20,
            'D' => 50,
            'E' => 20,
            'F' => 20,
            'G' => 50,
            'H' => 20,
            'I' => 20,
            'J' => 20,
        ];
    }
}
